package com.ruoyi.web;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.ruoyi.system.domain.EduStudent;
import com.ruoyi.system.service.IEduStudentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Description;
import org.springframework.core.NestedExceptionUtils;

import java.time.LocalDate;
import java.util.function.Function;

@Configuration
public class StudentTools {
	@Autowired
	private IEduStudentService eduStudentService;

	private static final Logger logger = LoggerFactory.getLogger(StudentTools.class);



	public record DeleteStudentDatesRequest(String sno) {
	}

	public record AddStudentDataRequest(String name, String sno,String sex) {
	}

//	@JsonInclude(Include.NON_NULL)//
//	public record BookingDetails(String bookingNumber, String name, LocalDate date,
//			String from, String to, String bookingClass) {
//	}



	@Bean
	@Description("删除学生")
	public Function<DeleteStudentDatesRequest, String> deleteStudent() {
		return request -> {
			System.out.println(request.sno);
			eduStudentService.deleteEduStudentBySno(request.sno);
//			flightBookingService.changeBooking(request.bookingNumber(), request.name(), request.date(), request.from(),
//					request.to());
			return "";
		};
	}

	@Bean
	@Description("添加学生")
	public Function<AddStudentDataRequest, String> addStudent() {
		return request -> {
			System.out.println(request.name);
			System.out.println(request.sno);
			System.out.println(request.sex);
			EduStudent student =new EduStudent();
			student.setName(request.name);
			student.setSno(request.sno);
			student.setSex(request.sex);
			eduStudentService.insertEduStudent(student);
			//flightBookingService.cancelBooking(request.bookingNumber(), request.name());
			return "";
		};
	}

}
